<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;padding: 0;
        }
        li{
            list-style: none;
            display: inline-block;
            width: 27px;
            height: 27px;
            background: url(./imgs/star.gif)no-repeat 0px 0px;
        }
    </style>
</head>
<body>
    <ul>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</body>
<script>
    var arr=document.getElementsByTagName("li");
    for(let i=0;i<arr.length;i++){
        arr[i].index=i;
        arr[i].onclick=function(){
            for(let j=0;j<arr.length;j++){
                arr[j].style.backgroundPosition="0px 0px";
            }
            for(let j=0;j<this.index+1;j++){
                arr[j].style.backgroundPosition="0px -29px"
            }
        }
        arr[i].onmouseover=function(){
            for(let j=0;j<arr.length;j++){
                arr[j].style.backgroundPosition="0px 0px";
            }
            for(let j=0;j<this.index+1;j++){
                arr[j].style.backgroundPosition="0px -29px"
            }
        }
    }
</script>
</html>